﻿using Hxj.Data;
using RecruitStudents.Client.DAL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Json;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RecruitStudents.BLL.Comm.Impl
{
    public class BLLComm
    {
        DALComm dal = new DALComm();
        public DataTable GetEaxmLogTable(string strSigUpID, string strSignUpStudentsSpecialityID, string strSpecialityKindsNO, string strExamPlaceNo)
        {
            WhereClip wcp = new WhereClip();
            if (!string.IsNullOrEmpty(strSigUpID))
            {
                wcp = wcp.And(TB_Exam_Log._.SignUpID == strSigUpID);
            }
            if (!string.IsNullOrEmpty(strSignUpStudentsSpecialityID))
            {
                wcp = wcp.And(TB_Exam_Log._.SignUpStudentsSpecialityID == strSignUpStudentsSpecialityID);
            }
            if (!string.IsNullOrEmpty(strSpecialityKindsNO))
            {
                wcp = wcp.And(TB_Exam_Log._.SpecialityKindsNO == strSpecialityKindsNO);
            }
            if (!string.IsNullOrEmpty(strExamPlaceNo))
            {
                wcp = wcp.And(TB_Exam_Log._.ExamPlaceNO == strExamPlaceNo);
            }
            return dal.GetTable<TB_Exam_Log>(wcp);
        }

        public JsonMessage SaveExamLog(string strJson)
        {
            JsonMessage json = null;
            if (strJson.IsNullOrEmptyString())
            {
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:参数Json为空，无法转换";
            }
            else
            {
                try
                {
                    TB_Exam_Log model = strJson.ToList<TB_Exam_Log>();
                    dal.Save<TB_Exam_Log>(model);
                    json = new JsonMessage();
                    json.State = "true";
                    json.Msg = "操作成功";
                }
                catch (Exception ex)
                {
                    json = new JsonMessage();
                    json.State = "false";
                    json.Msg = "操作失败:" + ex.Message;
                }
            }
            return json;
        }



        public DataTable GetExamLevelTable()
        {
            return dal.GetExamLevelTable();
        }


        /// <summary>
        /// 根据身份证号码解析出出生日期，性别 
        /// </summary>
        /// <param name="strIdentityCard"></param>
        /// <returns></returns>
        public List<string> GetBirthSexByIdCard(string strIdentityCard)
        {
            return dal.GetBirthSexByIdCard(strIdentityCard);
        }

        /// <summary>
        /// 根据高考号获取生源地,如果解析出一个生源地只读，大于一个可以让用户来进行选择报考
        /// </summary>
        /// <param name="strNMT_SignUpID"></param>
        /// <returns></returns>
        public DataTable GetProviceTable(string strNMT_SignUpID)
        {
            return dal.GetProviceTable(strNMT_SignUpID);
        }

        /// <summary>
        /// 根据高考号获取生源地
        /// </summary>
        /// <param name="strNMT_SignUpID"></param>
        /// <returns></returns>
        private DataTable CheckNMT_SignUpID(string strNMT_SignUpID)
        {
            return dal.CheckNMT_SignUpID(strNMT_SignUpID);
        }

        /// <summary>
        /// 获取字典表维护
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public DataTable GetDicDataTableByDicTableName(string strTableName)
        {
            return dal.GetDicDataTableByDicTableName(strTableName);
        }

        /// <summary>
        /// 获取所有考点
        /// </summary>
        /// <returns></returns>
        public DataTable GetExamPlaceTable()
        {
            return dal.GetExamPlaceTable();
        }

        /// <summary>
        /// 获取考点列表（报名专用，需要用生源地过滤）
        /// </summary>
        /// <returns></returns>
        public DataTable GetExamPlaceTable(string strExamProvince)
        {
            return dal.GetExamPlaceTable(strExamProvince);
        }

        /// <summary>
        /// 根据考点获取专业（报名专用，需要用性别过滤）
        /// </summary>
        /// <param name="strExamPlaceID"></param>
        /// <returns></returns>
        public DataTable GetSpecialityKindsTableByExamPlaceID(string strExamPlaceID, string strSex)
        {
            return dal.GetSpecialityKindsTableByExamPlaceID(strExamPlaceID, strSex);
        }

        /// <summary>
        /// 根据考点,专业,级别获取分组  兼容报名获取初试考试时间   
        /// </summary>
        /// <param name="examPlaceNo"></param>
        /// <param name="specialityKindsNo"></param>
        /// <param name="examLevel"></param>
        /// <returns></returns>
        public DataTable GetAppointmentGroupDataTable(string strExamPlaceNO, string strSpecialityKindsNO, string strExamLevel)
        {
            return dal.GetAppointmentGroupDataTable(strExamPlaceNO, strSpecialityKindsNO, strExamLevel);
        }

        /// <summary>
        /// 验证身份证号或高考报名号是否存在
        /// </summary>
        /// <param name="strIdCard">身份证号</param>
        /// <param name="strNMT_SignUpID">高考报名号</param>
        /// <param name="strFlag">0验证身份证号，1验证高考报名号</param>
        /// <returns></returns>
        public JsonMessage StudentInfoModify_CheckIsRegist(string strIdCard, string strNMT_SignUpID, string strFlag)
        {
            return dal.StudentInfoModify_CheckIsRegist(strIdCard, strNMT_SignUpID, strFlag);
        }

        /// <summary>
        /// 根据考点和专业生成准考证号
        /// </summary>
        /// <param name="strExamPlaceID"></param>
        /// <param name="strSpecialityKindsNO"></param>
        /// <returns></returns>
        public string CreateExamAllowExamID(string strExamPlaceID, string strSpecialityKindsNO, string strExamYear)
        {
            return dal.CreateExamAllowExamID(strExamPlaceID, strSpecialityKindsNO, strExamYear);
        }
        /// <summary>
        /// 生成订单编号
        /// </summary>
        /// <param name="strExamPlaceID"></param>
        /// <param name="strSpecialityKindsNO"></param>
        /// <returns></returns>
        public string CreateOrderNo()
        {
            return dal.CreateOrderNo();
        }

        /// <summary>
        /// 生成顺序抽签号
        /// </summary>
        /// <param name="strExamPlaceID"></param>
        /// <param name="strSpecialityKindsNO"></param>
        /// <returns></returns>
        public string CreateExamLotNO(string strExamPlaceNO, string strExamLevel, string strSpecialityKindsNO, string strExamYear)
        {
            return dal.CreateExamLotNO(strExamPlaceNO, strExamLevel, strSpecialityKindsNO, strExamYear);
        }

        /// <summary>
        /// 生成抽签号,开始号和最大号
        /// </summary>
        /// <param name="appointmentgroupid"></param>
        /// <returns></returns>
        public string CreateLotteryNO(string appointmentgroupid)
        {
            return dal.CreateLotteryNO(appointmentgroupid);
        }

        #region 获取 生源地信息
        public DataTable GetExamProvinceDataTable()
        {
            return dal.GetExamProvinceDataTable();
        }
        #endregion
    }
}
